package com.hy.wsroom.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author hy
 * 房间
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Room {
    private String roomId;
    private String name;
    private String description;

    private Set<Client> clients;

    /**
     * 是否存在客户端
     * @param client
     * @return
     */
    public boolean hasClient(Client client) {
        return clients.contains(client);
    }

    public boolean hasClient(Object clientId) {
        for (Client client : clients) {
            if (Objects.equals(client.getId(), clientId)) {
                return true;
            }
        }
        return false;
    }

    public Client getClient(Object clientId) {
        for (Client client : clients) {
            if (Objects.equals(client.getId(), clientId)) {
                return client;
            }
        }
        return null;
    }

    public void removeClient(Client client) {
        clients.remove(client);
    }

    public void removeClient(Object clientId) {
        for (Client client : clients) {
            if (Objects.equals(client.getId(), clientId)) {
                clients.remove(client);
                break;
            }
        }
    }

    public void addClient(Client client) {
        clients.add(client);
    }



}
